<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>康纳天花系统后台</title>
<link href="/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="/css/admins/base.css" rel="stylesheet" type="text/css">
<link href="/css/plugs/jDatepicker/jDatepicker-min.css"  rel="stylesheet"  /> 
<style type="text/css">
.layui-layer-btn a {
    width: 60px;
	float:left;
	text-align: center;
}
.layui-layer-btn{
	padding: 0 60px 47px !important;
}
</style>
<script src="/js/plugs/jquery.js"></script>
<script src="/js/admins/base.js"></script>
<script src="/js/layer/layer.js"></script>
<script src="/js/plugs/jDatepicker/jDatepicker-min.js"></script>
<script src="/js/admins/salesman_manage.js"></script>

    
    <script type="text/javascript">
function addmenu(){
	var selectObj = '<span class="memu_add_tit">分类名:</span><select id="addMenus" style="margin:20px 0;"><option value="0">新顶级菜单</option>';
	{#foreach key=key item=item from=$topMenu#} 
		selectObj += '<option value="{#$item.MENUID#}" >{#$item.MENUNAME#}</option>';
	{#/foreach#}
	selectObj +='</select>';
	var inputObj = '<span class="memu_add_tit">菜单名:</span><input type="text" id="addMenuName"/><span class="nameTips"></span>';
	var actionObj = '<div class="addMenuActionDiv" style="display:none;"><span class="memu_add_tit">动作名:</span><input style="margin:20px 0;" type="text" id="addMenuAction" /><span class="actionTips"></span></div>';
	var btnObj = '<input type="button"  value="确定" style=" margin-left:100px;" id="addMenuBtn"/>';
	layer.open({
		type: 1,   //0-4的选择,
		title: '添加新菜单',
		border: [0],
		area: ['460px', '280px'],
		shadeClose:false,
		content: '<div  class="memu_add"><div style="padding:10px;">'+selectObj+'<br/>'+inputObj+'<br/>'+actionObj+'<br/>'+btnObj+'</div></div>'
	});
}

$(function(){
	$(document).on("change","#addMenus",function(){   //切换添加动作inpput
		if($(this).val()<100){
			$(".addMenuActionDiv").css('display','none');
		}else{
			$(".addMenuActionDiv").css('display','');
		}
	});
	
	$(document).on("click","#addMenuBtn",function(){ //添加菜单
		var name = encodeURIComponent($("#addMenuName").val());
		var action = $("#addMenuAction").val();
		var id = $("#addMenus").val();
		if(name==''){
			$(".nameTips").css('color','red').html('请输入菜单名!');
			return false;
		}else{
			if(id>100){
				if(action==''){
					$(".actionTips").css('color','red').html('请输入动作名!');
					return false;
				}
			}
			$.post('menu_manage-cmd-addMenu.html',{name:name,id:id,action:action},function(data){	　//默认类型检查菜单
				if(data=='success'){
					location.reload();
				}else if(data=='namefail'){
					$(".nameTips").css('color','red').html('菜单名重复！');
					return false;
				}else if(data=='actionfail'){
					$(".actionTips").css('color','red').html('动作名重复！');
					return false;
				}else{
					alert("添加失败！");
				}
			});
		}
	});

	$(".delMenu").click(function(){　　//删除菜单
		var id  =$(this).attr("lang");
		if(id<1000){  //顶级菜单
			word  = '删除该顶级菜单将删除所有下级菜单！';
		}else{
			word = '确定删除该菜单吗？';
		}
		var obj = $(this);
		layer.confirm(word,{
			btn:['是','否'],
			//area: ['400px', '200px']
		},function(){
			$.post('menu_manage-cmd-delMenu.html',{id:id},function(data){
				if(data=='1'){
					if(id<1000){
						location.reload();
					}else{
						obj.parent().parent().remove();
						layer.closeAll();
					}
				}else{
					layer.msg("删除失败！");
					location.reload();
				}
			});
		},function(){
			layer.closeAll();
		});
		
		
	
	
	});
	$(".changeIsshow").click(function(){　　//切换是否显示
		id = $(this).attr("lang");
		type = $(this).attr("alt");
		type = type == 1 ? 0 : 1;
		obj = $(this);
		$.post('menu_manage-cmd-changeMenuIsshow.html',{id:id,type:type},function(data){
			if(data=='1'){
				if(type==1){
					src = "http://i2.ymfile.com/images/admin/yes.gif";
				}else{
					src = "http://i2.ymfile.com/images/admin/no.gif";
				}
				obj.attr("alt",type);
				obj.attr("src",src);
			}else{
				alert('更改失败！');
			}
		});
	
	});
	
	$(".changeAction").click(function(){　　　//更改动作
		var td = $(this);
		var txt = td.text();
		var input = $("<input type='text' value='"+txt+"'/>");
		td.html(input);
		input.click(function(){
			return false;
		})
		input.trigger("focus");
		input.blur(function(){
			var newtxt = $(this).val();
			if(newtxt != txt){
				td.html(newtxt);
				var id = td.attr("lang");
				var action = newtxt;
				$.post('menu_manage-cmd-changeMenuAction.html',{id:id,action:action},function(data){
					if(data=='1'){
						td.html(newtxt);
					}else{
						if(data=='0'){
							alert("参数错误!");
						}else{
							alert("访动作已经存在");
						}
						td.html(txt);
						return;
					}				
				});
			}else{
				td.html(newtxt);
			}
		});
	});
	
	
	$(".changeName").click(function(){　//更改菜单名
		var td = $(this);
		var txt = td.text();
		var input = $("<input type='text' value='"+txt+"'/>");
		td.html(input);
		input.click(function(){
			return false;
		});
		input.trigger("focus");
		input.blur(function(){
			var newtxt = $(this).val();
			if(newtxt !=txt){
				td.html(newtxt);
				var id = td.attr("lang");
				var name = encodeURIComponent(newtxt);
				$.post('menu_manage-cmd-changeMenuName.html',{id:id,name:name},function(data){
					if(data=='1'){
						td.html(newtxt);
					}else{
						if(data=='0'){
							alert("参数错误!");
						}else{
							alert("访分类已经存在");
						}
						td.html(txt);
						return;
					}				
				});
			}else{
				td.html(newtxt);
			}
		});
	});
});

function showSub(id){　　　//显示二级菜单
	if($(".sub"+id).css("display")=='none'){
		$(".top"+id).html("-");
		$(".sub"+id).css("display","");
	}else{
		$(".top"+id).html("+");
		$(".sub"+id).css("display","none");
	}
}


	
</script>
    
</head>

<body>

<!-- nav start-->
{# include file="$tpl_root_path/admins/base/navbar.html" #}
<!-- nav end -->    
    
    
    
    
<div class="container-fluid">
    
      <div class="row">
      
    <!-- left  box start-->     
       {# include file="$tpl_root_path/admins/base/left_menu.html" #}
    <!-- left  box end-->        
 
  <!-- right  box start-->  
         
     <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main right-box">
          
          <div class="menu-navbar">{#$menu_navbar#}</div>
          <h3 class="page-header">菜单管理 </h3>

             <div class="tool-list-box">
              <a id="addMenu" onClick="addmenu();" class="btn btn-warning">添加菜单</a>
          </div>
    
          <div class="info-list-box">
            
             
              <table class="table table-hover">
                    <tr>
                  <td width="25%" height="28" bgcolor="#C9EBF5" class="line_06">菜单名</td>
				  <td width="29%" height="28" bgcolor="#C9EBF5" class="line_06">动作名</td>
                  <td width="29%" height="28" bgcolor="#C9EBF5" class="line_06">是否显示</td>
                  <td width="27%" height="28" bgcolor="#C9EBF5" class="line_06">功能操作</td>
                  </tr>
{#foreach key=key item=item from=$mysqlData#}               
		<tr  style=" cursor:pointer;">
		  <td height="25"  class="t8" style="text-align:left;"><a class="top{#$item.MENUID#}" href="javascript:showSub({#$item.MENUID#});">+</a>&nbsp;<span lang="{#$item.MENUID#}" class="changeName">{#$item.MENUNAME#}</span></td>
		  <td height="25"  class="t8"></td>
		  <td height="25"  class="t8"><img src="http://i2.ymfile.com/images/admin/{#if $item.ISSHOW eq 1#}yes{#else#}no{#/if#}.gif" class="changeIsshow" lang="{#$item.MENUID#}" alt="{#$item.ISSHOW#}"/></td>
		  <td height="25"  class="t8" style="cursor:hand"><a href="javascript:void(0)" class="delMenu" lang={#$item.MENUID#}>删除</a> </td>
		</tr>
		{#if $item.SUB#}
		{#foreach item =i from = $item.SUB#}
			<tr class="sub{#$item.MENUID#}" style="display:none;cursor:pointer;" >
			  <td height="25"  class="t8" style="text-align:left;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span lang="{#$i.MENUID#}" class="changeName">{#$i.MENUNAME#}</span></td>
			  <td height="25"  class="t8"><span class="changeAction"  lang="{#$i.MENUID#}">{# $i.ACTION#}</span></td>
			  <td height="25"  class="t8"><img src="http://i2.ymfile.com/images/admin/{# if $i.ISSHOW eq 1#}yes{#else#}no{#/if#}.gif" class="changeIsshow" lang="{#$i.MENUID#}" alt="{#$i.ISSHOW#}" /></td>
			  <td height="25"  class="t8" style="cursor:hand"><a href="javascript:void(0)" class="delMenu" lang={#$i.MENUID#}>删除</a> </td>
			</tr>
		{#/foreach#}
		{#/if#}
{#/foreach#} 
              </table>

                  
                 
      </div>
          
         

          
     </div>
 
  <!-- right  box end-->         
        
      </div>
</div>



</body>
</html>
